package oaSystem.biz.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import oaSystem.biz.FunctionBiz;
import oaSystem.entity.Function;
import oaSystem.mapper.FunctionMapper;
@Service
public class FunctionBizImpl implements FunctionBiz {
	@Autowired
	public FunctionMapper functionMapper;
	@Override
	public List<Function> findAllFunction() {
		List<Function> list = functionMapper.findAllFunction();
		List<Function> fu = new ArrayList<Function>();
		Function f=null;
		for (Function function : list) {
			if(function.getParentId()==null){
				 f=function;
				 f.setChildren(functionMapper.findFunctionByParentId(f.getId()));
				 findChildren(f);	
				 fu.add(f);
				 
			}
		}
		return fu;
	}
	private void findChildren(Function f) {
		List<Function> children = f.getChildren();
		 for (Function fu2 : children) {
			 fu2.setChildren(functionMapper.findFunctionByParentId(fu2.getId()));
			 findChildren(fu2);
		 }
	}

}
